// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/functions/registerer.h>
#include <pollux/functions/prestosql/array_functions.h>

namespace kumo::pollux::functions {
    namespace {
        template<typename T>
        inline void registerArrayConcatFunctions(const std::string &prefix) {
            register_function<
                ParameterBinder<ArrayConcatFunction, T>,
                Array<T>,
                Array<T>,
                T>({prefix + "concat"});
            register_function<
                ParameterBinder<ArrayConcatFunction, T>,
                Array<T>,
                T,
                Array<T> >({prefix + "concat"});
            register_function<
                ParameterBinder<ArrayConcatFunction, T>,
                Array<T>,
                Variadic<Array<T> > >({prefix + "concat"});
        }
    } // namespace

    void registerArrayConcatFunctions(const std::string &prefix) {
        registerArrayConcatFunctions<Generic<T1> >(prefix);
        // Fast paths for primitives types.
        registerArrayConcatFunctions<int8_t>(prefix);
        registerArrayConcatFunctions<int16_t>(prefix);
        registerArrayConcatFunctions<int32_t>(prefix);
        registerArrayConcatFunctions<int64_t>(prefix);
        registerArrayConcatFunctions<int128_t>(prefix);
        registerArrayConcatFunctions<float>(prefix);
        registerArrayConcatFunctions<double>(prefix);
        registerArrayConcatFunctions<bool>(prefix);
        registerArrayConcatFunctions<Varchar>(prefix);
        registerArrayConcatFunctions<Timestamp>(prefix);
        registerArrayConcatFunctions<Date>(prefix);
    }
} // namespace kumo::pollux::functions
